package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Depot;
import cn.wolfcode.crm.mapper.DepotMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DepotServiceImpl implements IDepotService {

    @Autowired
    private DepotMapper depotMapper;

    public void insert(Depot entity) {
        entity.setInputTime(new Date());//设置当前时间为添加时间
        depotMapper.insert(entity);
    }

    public void delete(Long id) {
        depotMapper.deleteByPrimaryKey(id);
    }

    public void update(Depot entity) {
        depotMapper.updateByPrimaryKey(entity);
    }

    public Depot get(Long id) {
        return depotMapper.selectByPrimaryKey(id);
    }

    public List<Depot> list() {
        return depotMapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int total = depotMapper.queryForCount(qo);
        List<Depot> rows = depotMapper.queryForList(qo);
        return new PageResult(total,rows);
    }
}
